/*
Run this script on:

        mssql-ct.db.jwan.it,1433.Caronte2013    -  This database will be modified

to synchronize it with:

        kalgan01.cs.jwan.it,1443.Jambo2014_sviluppo

You are recommended to back up your database before running this script

Script created by SQL Compare version 9.0.0 from Red Gate Software Ltd at 10/04/2014 14:54:27

*/
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Dropping extended properties'
GO
EXEC sp_dropextendedproperty N'MS_Description', 'SCHEMA', N'dbo', 'TABLE', N'fatture', 'COLUMN', N'CF'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[convenzioni_tipo_auth]'
GO
ALTER TABLE [dbo].[convenzioni_tipo_auth] DROP CONSTRAINT [PK_convenzioni_tipo_auth]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[fatture]'
GO
ALTER TABLE [dbo].[fatture] DROP CONSTRAINT [DF_fatture_CF]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[db_version]'
GO
ALTER TABLE [dbo].[db_version] ADD
[BACKUP_TS] [datetime] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[convenzioni_config_tipo_auth]'
GO
ALTER TABLE [dbo].[convenzioni_config_tipo_auth] ADD
[PATTERN] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[convenzioni_tipo_auth]'
GO
ALTER TABLE [dbo].[convenzioni_tipo_auth] ALTER COLUMN [CODTIPOAUTH] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_convenzioni_tipo_auth] on [dbo].[convenzioni_tipo_auth]'
GO
ALTER TABLE [dbo].[convenzioni_tipo_auth] ADD CONSTRAINT [PK_convenzioni_tipo_auth] PRIMARY KEY CLUSTERED  ([CODTIPOAUTH])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[formule]'
GO
ALTER TABLE [dbo].[formule] ADD
[TAXPERDETPAX] [bit] NOT NULL CONSTRAINT [DF_formule_TAXPERDETPAX] DEFAULT ((0))
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[fatture]'
GO
ALTER TABLE [dbo].[fatture] DROP
COLUMN [CF]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[convenzioni_config_tipo_auth]'
GO
ALTER TABLE [dbo].[convenzioni_config_tipo_auth] ADD
CONSTRAINT [FK_convenzioni_config_tipo_auth_convenzioni] FOREIGN KEY ([CODCONV]) REFERENCES [dbo].[convenzioni] ([CODCONV]),
CONSTRAINT [FK_convenzioni_config_tipo_auth_convenzioni_tipo_auth] FOREIGN KEY ([CODTIPOAUTH]) REFERENCES [dbo].[convenzioni_tipo_auth] ([CODTIPOAUTH])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating extended properties'
GO
EXEC sp_addextendedproperty N'MS_Description', N'timestamp del backup di riferimento. ha senso solo per gli ambienti di test derivati dalla produzione', 'SCHEMA', N'dbo', 'TABLE', N'db_version', 'COLUMN', N'BACKUP_TS'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering permissions on [dbo].[convenzioni_config_tipo_auth]'
GO
GRANT SELECT ON  [dbo].[convenzioni_config_tipo_auth] TO [JamboGest]
GRANT INSERT ON  [dbo].[convenzioni_config_tipo_auth] TO [JamboGest]
GRANT DELETE ON  [dbo].[convenzioni_config_tipo_auth] TO [JamboGest]
GRANT UPDATE ON  [dbo].[convenzioni_config_tipo_auth] TO [JamboGest]
GO
PRINT N'Altering permissions on [dbo].[convenzioni_tipo_auth]'
GO
GRANT SELECT ON  [dbo].[convenzioni_tipo_auth] TO [JamboGest]
GRANT INSERT ON  [dbo].[convenzioni_tipo_auth] TO [JamboGest]
GRANT DELETE ON  [dbo].[convenzioni_tipo_auth] TO [JamboGest]
GRANT UPDATE ON  [dbo].[convenzioni_tipo_auth] TO [JamboGest]
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO
